#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    int cal(int* arr) {
        int ans = 0;
        for (int i = 31; i >= 0; --i) {
            if (arr[i]) {
                ans |= (1 << (31 - i));
            }
        }
        return ans;
    }
    void tran(int* arr, int num,int character) {
        int now = 31;
        while (num) {
            if (num % 2) {
                arr[now]+=character;
            }
            --now;
            num /= 2;
        }
    }
    int minimumSubarrayLength(vector<int>& nums, int k) {
        if (k == 0)
            return 1;
        int arr[32] = { 0 };
        int ans = INT_MAX, now = 0;
        for (int left = 0, right = 0; right < nums.size(); ++right) {
            tran(arr, nums[right],1);
            now = cal(arr);
            while (now >= k) {
                ans = min(ans, right - left + 1);
                tran(arr, nums[left++],-1);
                now = cal(arr);
            }
        }
        return ans == INT_MAX ? -1 : ans;
    }
};